package com.ultrasoft.farmasoft.repository;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.ultrasoft.farmasoft.domain.Accountspayable;

@Repository(value = "accountsPayableDao")
@Transactional(readOnly = false)
public class AccountsPayableDaoImpl implements AccountsPayableDao {

	private EntityManager em = null;
	@PersistenceContext
	public void setEntityManager(EntityManager em) {
		this.em = em;
	}
	public List<Accountspayable> getListAccountsPayable() {
		TypedQuery<Accountspayable> q = em.createNamedQuery("Accountspayable.findAll",Accountspayable.class);
    	return q.getResultList();
	}

	public List<Accountspayable> getListAccountsPayableByProviderId(Integer providerId) {
		TypedQuery<Accountspayable> q = em.createNamedQuery("Accountspayable.findByProviderId",Accountspayable.class);
    	q.setParameter("providerId",providerId);
    	return q.getResultList();
	}

	public void remove(Accountspayable accountsPayable) {
		em.remove(em.getReference(Accountspayable.class,accountsPayable.getAccountsPayableId()));
	}

	public void update(Accountspayable accountsPayable) {
		em.merge(accountsPayable);
	}

	public void add(Accountspayable accountsPayable) {
		em.persist(accountsPayable);
	}

	public Accountspayable findAccountsPayableByAccountsPayableId(Integer accountsPayableId) {
		Accountspayable res = null;
		try {
			res=em.find(Accountspayable.class,accountsPayableId);
		} catch (Exception e) {
			// TODO: handle exception
		}
    	return res;
	}
}
